package com.ruoyi.web.controller.system;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysCarInfo;
import com.ruoyi.system.domain.vo.IndexVo;
import com.ruoyi.system.domain.vo.StatisticsVO;
import com.ruoyi.system.service.IJjzApplyService;
import com.ruoyi.system.service.ISysCarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/index")
public class SysCarInfoController extends BaseController
{
    @Autowired
    private ISysCarInfoService carInfoService;

    @Autowired
    private IJjzApplyService jjzApplyService;

    @Autowired
    private RedisCache redisCache;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysCarInfo sysCarInfo)
    {
        startPage();
        List<IndexVo> list = carInfoService.selectIndexList(sysCarInfo);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCarInfo sysCarInfo)
    {
        List<SysCarInfo> list = carInfoService.selectCarInfoList(sysCarInfo);
        ExcelUtil<SysCarInfo> util = new ExcelUtil<SysCarInfo>(SysCarInfo.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carInfoService.selectCarInfoById(id));
    }

    /**
     * 新增【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCarInfo sysCarInfo)
    {
        return toAjax(carInfoService.insertCarInfo(sysCarInfo));
    }

    /**
     * 修改【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCarInfo sysCarInfo)
    {
        return toAjax(carInfoService.updateCarInfo(sysCarInfo));
    }


    /**
     * 修改状态
     */

    @Log(title = "【修改状态】", businessType = BusinessType.UPDATE)
    @PutMapping("/status")
    public AjaxResult status(@RequestParam("id")Long id,@RequestParam("status")Boolean status)
    {
        return toAjax(carInfoService.status(id,status));
    }

    /**
     * 删除【请填写功能名称】
     */

    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carInfoService.deleteCarInfoByIds(ids));
    }

    /**
     * 查看申请详情
     */

    @GetMapping("/getDetail")
    public AjaxResult getDetail(@RequestParam("auth")String auth)
    {
        HashMap header = new HashMap();
        header.put("Authorization", auth);
        String res = HttpUtils.sendPost(RuoYiConfig.getJjzPath() + "/pro/applyRecordController/stateList", "", header);
        JSONObject jsonObject = JSONObject.parseObject(res);
        return AjaxResult.success(jsonObject);
    }


    /**
     * 修改状态
     */

    @Log(title = "【修改类型】", businessType = BusinessType.UPDATE)
    @PutMapping("/jjzzl")
    public AjaxResult status(@RequestParam("id")Long id,@RequestParam("jjzzl")String jjzzl)
    {
        return toAjax(carInfoService.jjzzl(id,jjzzl));
    }


    /**
     * 统计
     */

    @GetMapping("/statistics")
    public AjaxResult statistics()
    {
        StatisticsVO statisticsVO = carInfoService.statistics();
        return AjaxResult.success(statisticsVO);
    }




    /**
     * 删除【请填写功能名称】
     */

    @GetMapping("/test")
    public AjaxResult test()
    {
        //jjzApplyService.checkApplyJjz("");
        //jjzApplyService.jjzApply();
        redisCache.setCacheObject("APPLY_02a4a1d5840741329ef56d2945a1c27f","冀B6G2N2",2, TimeUnit.MINUTES);
       // jjzApplyService.checkApplyJjz("e1d33ff35d0248f587c1da7da126db8e");
        return toAjax(true);
    }
}
